/**
 * The file for the Button class.
 */

package edu.gatech.interaction;

import java.awt.Color;
import java.awt.Font;
import java.awt.FontMetrics;
import java.awt.Graphics2D;

/**
 * The Class Button.
 * @author Hippie Mind Control
 * @version 1.0
 */
public class Button {
	
	/** The height. */
	private int x, y, width, height;
	
	/** The text. */
	private String text;
	
	/** The text color. */
	private Color buttonColor, textColor;
	
	/** The visibility */
	private boolean visible;
	
	//Class constructor
	/**
	 * Instantiates a new button.
	 *
	 * @param x the x
	 * @param y the y
	 * @param width the width
	 * @param height the height
	 * @param text the text
	 */
	public Button(int x, int y, int width, int height, String text) {
		this.x = x;
		this.y = y;
		this.width = width;
		this.height = height;
		this.text = text;
		buttonColor = Color.GRAY;
		textColor = Color.WHITE;
		visible = true;
	}
	
	//Checks to make sure that the x and y location are somewhere on the button
	/**
	 * Contains.
	 *
	 * @param x1 the x1
	 * @param y1 the y1
	 * @return true, if successful
	 */
	public boolean contains(int x1, int y1) {
		return (x <= x1 && x1 <= (x + width) && y <= y1 && y1 <= (y + height));
	}
	
	//Draws button
	/**
	 * Draw.
	 *
	 * @param g2d the g2d
	 */
	public void draw(Graphics2D g2d) {
		if(visible) {
			g2d.setColor(buttonColor);
			g2d.fillRect(x, y, width, height);
			g2d.setColor(Color.BLUE);
			g2d.drawRect(x, y, width, height);
			g2d.setColor(textColor);
			g2d.setFont(new Font("Trebuchet MS", Font.PLAIN, 30));
			FontMetrics fm = g2d.getFontMetrics();
			int textWidth = fm.stringWidth(text);
			int textHeight = fm.getHeight();
			g2d.drawString(text, x + (width - textWidth) / 2, y + (height + textHeight / 2) / 2);
		}
	}
	
	//Getters and Setters
	/**
	 * Gets the button color.
	 *
	 * @return the button color
	 */
	public Color getButtonColor() {
		return buttonColor;
	}
	
	/**
	 * Sets the button color.
	 *
	 * @param buttonColor the new button color
	 */
	public void setButtonColor(Color buttonColor) {
		this.buttonColor = buttonColor;
	}
	
	/**
	 * Gets the text color.
	 *
	 * @return the text color
	 */
	public Color getTextColor() {
		return textColor;
	}
	
	/**
	 * Sets the text color.
	 *
	 * @param textColor the new text color
	 */
	public void setTextColor(Color textColor) {
		this.textColor = textColor;
	}
	
	/**
	 * Gets the x.
	 *
	 * @return the x
	 */
	public int getX() {
		return x;
	}
	
	/**
	 * Sets the x.
	 *
	 * @param x1 the new x
	 */
	public void setX(int x1) {
		x = x1;
	}
	
	/**
	 * Gets the y.
	 *
	 * @return the y
	 */
	public int getY() {
		return y;
	}
	
	/**
	 * Sets the y.
	 *
	 * @param y1 the new y
	 */
	public void setY(int y1) {
		y = y1;
	}
	
	/**
	 * Gets the width.
	 *
	 * @return the width
	 */
	public int getWidth() {
		return width;
	}
	
	/**
	 * Sets the width.
	 *
	 * @param width1 the new width
	 */
	public void setWidth(int width1) {
		width = width1;
	}
	
	/**
	 * Gets the height.
	 *
	 * @return the height
	 */
	public int getHeight() {
		return height;
	}
	
	/**
	 * Sets the height.
	 *
	 * @param height1 the new height
	 */
	public void setHeight(int height1) {
		height = height1;
	}
	
	/**
	 * Gets the text.
	 *
	 * @return the text
	 */
	public String getText() {
		return text;
	}
	
	/**
	 * Sets the text.
	 *
	 * @param text the new text
	 */
	public void setText(String text) {
		this.text = text;
	}
	
	/**
	 * Sets the visibility
	 * 
	 * @param visible The new visibility
	 */
	public void setVisible(boolean visible) {
		this.visible = visible;
	}
	
	/**
	 * Returns a string version of the button.
	 * @return The button in string form.
	 */
	public String toString() {
		return "Button";
	}
}
